﻿using System;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace GENERIC.EFRepository
{
    public abstract class EFMapping<TEntityType> : EntityTypeConfiguration<TEntityType> where TEntityType : class
    {
        #region Constructor

        public EFMapping() : this(null)
        {
        }

        protected EFMapping(string schemaName)
        {
            ToTable(TableName, schemaName);
            var obj = GetPrimaryKey();
            if (obj != null)
            {
                HasKey(obj);
            }
            MapProperties();
        }

        #endregion

        #region Properties

        protected abstract string TableName { get; }

        protected virtual Expression<Func<TEntityType, object>> GetPrimaryKey()
        {
            return null;
        }

        #endregion

        #region Methods

        protected abstract void MapProperties();

        #endregion
    }
}
